README file for Harbers and Ingram PSRM 2018
Paper: "Spatial Tools for Case Selection: Using LISAs to Design Mixed-Methods Research"

# ENVIRONMENT AND PACKAGES
Analysis was run using R 3.5.1 and Python 3.7.0. 
In R, the packages required are identified in setup script and loaded by running that script.
In python, the packages required for users are: pandas, numpy, pysal, and pyshp.
If python packages are not already installed on machine, users will need to install them first; script will then import them.
If using conda distribution, be sure to use "conda install" syntax to install packages (rather than "pip install") to avoid breaking packages.

# WORKING DIRECTORY
To replicate results in paper, copy all files to a folder you will use as working directory.
Note file path to this directory.

Open .R script marked "setup" and set working directory.
If this is done manually, then nothing needs to be done.
If you are going to set this using "setwd" syntax, then uncomment and edit line 67.
You only need to do this once in R. Do not set or change working directory again with analysis command file.
Note that you also need to set working directory in python script (.py; line 42).

Run file "harbersingram_psrm1_20181206_setup.R".
This file will load all required packages and create subdirectories within working directory set in previous step.

Once you run setup file, move this setup .R script and all other R and Python command files (.R and .py) to folder labeled "code".
Move all files with following extensions to folder marked "shapefiles": .shp, .dbf, .shx.
(This should be three files: NAT.dbf, NAT.shp, and NAT.shx.)

# ANALYSIS
From within "code" folder, open and run main R script, "harbersingram_psrm2_20181206_main.R".

Running this script will load data from shapefiles, execute analysis, and generate figures and tables reported in paper. 
In the process, this script sources the Python script automatically using the "reticulate" package in R (line 151). 
That is, the Python script does not need to be opened and executed separately.

The main script also saves the R workspace (.RData) on line 1108.
This data file is relatively large (700MB); if you do not want to generate this file, comment this line (begins "save.image...).
 
Lastly, the main script also automatically generates figures from appendix by sourcing the remaining R script, "harbersingram_psrm4_appendix_20181206.R" (line 1121).
If you do not want generate material from appendix, then comment this line (begins "source...").

#end
